package ext.tianma.supplier;

import java.util.List;

import wt.part.WTPart;
import wt.util.WTException;

import com.ptc.jca.mvc.components.JcaComponentParams;
import com.ptc.mvc.components.AbstractComponentBuilder;
import com.ptc.mvc.components.ColumnConfig;
import com.ptc.mvc.components.ComponentBuilder;
import com.ptc.mvc.components.ComponentConfig;
import com.ptc.mvc.components.ComponentConfigFactory;
import com.ptc.mvc.components.ComponentParams;
import com.ptc.mvc.components.TableConfig;
import com.ptc.mvc.util.ClientMessageSource;




/**Description:【供应商信息查询】的Builder
 * @author    :  YangWen
 * @create at :  2013-8-14   上午11:10:02
 */
@ComponentBuilder("ext.tianma.supplier.SupplierInfoQueryTableBuilder")
public class SupplierInfoQueryTableBuilder extends AbstractComponentBuilder {

	
	private ClientMessageSource msgSource;
	
	public SupplierInfoQueryTableBuilder() {		
		this.msgSource = getMessageSource("ext.tianma.supplier.SupplierRB");
	}	

	@Override
	public Object buildComponentData(ComponentConfig arg0, ComponentParams componentparams) throws Exception {
		
		String partOid = (String) ((JcaComponentParams) componentparams).getAttribute("partOid");
		if(partOid == null)
		    partOid = (String) componentparams.getParameter("partOid");
		
		System.out.println("WTPart oid="+partOid);
		
		List<WTPart>  result = SupplierInfoQueryBusiness.getSupplierInfomationData(partOid);
		
		System.out.println("输出的个数："+result.size());
		
		return result;
	}

	
	
	
	
	@Override
	public ComponentConfig buildComponentConfig(ComponentParams arg0) throws WTException {
		
		ComponentConfigFactory factory = getComponentConfigFactory();
		
		TableConfig result = factory.newTableConfig();
		
		result.setConfigurable(false);
		//result.setActionModel("folderbrowser_toolbar_exportlisttofile_submenu");
		result.setType("wt.fc.WTObject");
		result.setLabel(msgSource.getMessage("supplierInfo"));
		//result.setSelectable(true);
		
		
		ColumnConfig partSupplierWithSystemName = factory.newColumnConfig("partSupplierWithSystemName", true);
		partSupplierWithSystemName.setLabel(msgSource.getMessage("partSupplierWithSystemName"));
		result.addComponent(partSupplierWithSystemName);		
		
		
		ColumnConfig partNumber = factory.newColumnConfig("number", true);
		partNumber.setLabel(msgSource.getMessage("partNumber"));
		result.addComponent(partNumber);		
		
		
		ColumnConfig partName = factory.newColumnConfig("name", true);
		partName.setLabel(msgSource.getMessage("partName"));
		result.addComponent(partName);
				
		
		ColumnConfig view = factory.newColumnConfig("view", true);
		view.setLabel(msgSource.getMessage("view"));
		result.addComponent(view);
				
		
		ColumnConfig stateState = factory.newColumnConfig("state.state", true);
		stateState.setLabel(msgSource.getMessage("stateState"));
		result.addComponent(stateState);
				
		
		ColumnConfig isSecondSupplier = factory.newColumnConfig("isSecondSupplier", true);
		isSecondSupplier.setLabel(msgSource.getMessage("isSecondSupplier"));
		result.addComponent(isSecondSupplier);					
		
		return result;		
		
	}
	
	

}
